package com.zygk.locationtool.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.zygk.library.adapter.BaseListAdapter;
import com.zygk.library.view.FixedListView;
import com.zygk.locationtool.R;
import com.zygk.locationtool.model.M_Station;
import com.zygk.locationtool.model.M_Town;
import java.util.List;

/**
 * 站点列表适配器
 * created by Djy
 * 2018/6/6 0006 下午 2:14
 */
public class StationListParentAdapter extends BaseListAdapter<M_Town> {
    private int pagePos;

    public void setPagePos(int pagePos) {
        this.pagePos = pagePos;
    }

    public StationListParentAdapter(Context context, List<M_Town> list) {
        super(context, list);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_site_list_title, null, false);
            holder = new ViewHolder(convertView);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final M_Town m = getItem(position);
        holder.tvTownName.setText(m.getTownName() + "（" + m.getStationCount() + "个监测点）");

        if (m.getStationList() != null && !m.getStationList().isEmpty()) {
            holder.lvContent.setVisibility(View.VISIBLE);
            StationListSonAdapter sonAdapter = new StationListSonAdapter(mContext, m.getStationList());
            sonAdapter.setOnItemClickListener(onItemClickListener);
            holder.lvContent.setAdapter(sonAdapter);
        } else {
            holder.lvContent.setVisibility(View.GONE);
        }

        return convertView;
    }

    public interface onItemClickListener {
        void onItemClick(M_Station station);
    }

    private onItemClickListener onItemClickListener;

    public void setOnItemClickListener(StationListParentAdapter.onItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    static class ViewHolder {
        @BindView(R.id.tv_TownName)
        TextView tvTownName;
        @BindView(R.id.lv_content) FixedListView lvContent;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
